package org.nf.dao.impl;

import org.nf.dao.UserDao;
import org.nf.entity.User;
import org.nf.utils.DbUtil;
import org.nf.utils.SqlRunner;

import java.sql.Connection;
import java.util.List;

/**
 * @Author lzp
 * @Date 2024-04-22
 */
public class UserDaoImpl implements UserDao {
    @Override
    public User selectUser(String username, String password) {
        // 第一：定义要操作的 SQL 语句
        String sql = "select * from user where username=? and password=?";

        //获取连接对象 ，实例化sqlRunner
        Connection connection = DbUtil.getConnection();
        SqlRunner sqlRunner = new SqlRunner(connection);

        //执行 sql
        List<User> list = sqlRunner.query(User.class, sql, username, password);

        return list.isEmpty()?null:list.get(0);
    }
}
